<?php
namespace app\mall\controller;

use app\data\controller\api\Auth;
use app\mall\logic\deliveryAddressLogic;

class DeliveryAddress extends Auth{

    //添加地址
    public function address_add(){
        $param = array(
            'u_id' => $this->uuid,
            'consignee' => request()->param('consignee',''),//收货人
            'phone' => request()->param('phone',''),//手机号
            'local_area' => request()->param('local_area',''),//所在地区
            'full_address' => request()->param('full_address','')//详细地址
        );
        $logic = new deliveryAddressLogic();
        $res = $logic->address_add($param);
        if ($res) $this->success('地址添加成功');
        $this->error('地址添加失败','',500);
    }

    //地址列表
    public function address_list(){
        $logic = new deliveryAddressLogic();
        $data = $logic->address_list($this->uuid);
        $this->success('地址列表',$data);
    }

    //删除地址
    public function address_del(){
        $id = request()->param('id',0);
        $logic = new deliveryAddressLogic();
        $res = $logic->address_del($this->uuid,$id);
        if ($res) $this->success('删除地址成功');
        $this->error('删除地址失败','',500);
    }

    //地址详情
    public function address_details(){
        $id = request()->param('id',0);
        $logic = new deliveryAddressLogic();
        $data = $logic->address_details($this->uuid,$id);
        $this->success('地址详情',$data);
    }

    //修改地址
    public function address_edit(){
        $id = request()->param('id',0);
        $param = array(
            'consignee' => request()->param('consignee',''),//收货人
            'phone' => request()->param('phone',''),//手机号
            'local_area' => request()->param('local_area',''),//所在地区
            'full_address' => request()->param('full_address','')//详细地址
        );
        $logic = new deliveryAddressLogic();
        $res = $logic->address_edit($this->uuid,$id,$param);
        if ($res) $this->success('地址修改成功');
        $this->error('地址修改失败','',500);
    }

    //将地址设为默认
    public function address_default(){
        $id = request()->param('id',0);
        $logic = new deliveryAddressLogic();
        $res = $logic->address_default($this->uuid,$id);
        if ($res) $this->success('设置默认地址成功');
        $this->error('设置默认地址失败');
    }

}